% construct diffusion and random force part
function rest = randomtest(t,y,num,casenum)

load('alphas');
load('betas');
load('msval');
load('sigma');

dt1=0.5/num; 
t2courseindex=floor((t+0.5*dt1)/dt1)+1;
switch casenum
    case 1
        row=size(betas,1); colum=size(betas,2);
        if colum >=2
            rest(row)=0;
        end
%rest(1)=-1/2*sig(t2courseindex,1).^2;
%rest(2:row)=sig(t2courseindex,1)*msval(t2courseindex,1:colum);
        rest(1:row)=sig(t2courseindex,1:row);
%rest(1:row)=[1,zeros(1,row-1)];
    case 2
        row=size(betas,1); colum=size(betas,2);
        if colum >=2
            rest(row)=0;
        end
%rest(1)=-1/2*sig(t2courseindex,1).^2;
%rest(2:row)=sig(t2courseindex,1)*msval(t2courseindex,1:colum);
        rest(1)=sum(sig(t2courseindex,:).^2);
        rest(2:row)=2*sig(t2courseindex,2:row).*sig(t2courseindex,1);
%rest(1:row)=[1,zeros(1,row-1)];  
    case 3
        betarow=size(betas,1); alpharow=size(alphas,1);
        row=alpharow*betarow;
        if row >=2
            rest(row)=0;
        end
        for k=2:alpharow
            rest(betarow*(k-1)+1:k*betarow)=sig(t2courseindex,1:betarow)...
                *msval(t2courseindex,k-1);
        end
    case 4
        betarow=size(betas,1); alpharow=size(alphas,1);
        row=alpharow*betarow;
        if row >=2
            rest(row)=0;
        end
        rest(1)=-1/2*sum(sig(t2courseindex,:).^2);
        rest(2:betarow)=-sig(t2courseindex,2:betarow).*sig(t2courseindex,1);
        for k=2:alpharow
            rest(betarow*(k-1)+1:k*betarow)=sig(t2courseindex,1:betarow)...
                *msval(t2courseindex,k-1);
        end
    case 5
        betarow=size(betas,1);
        row=betarow;
        if row >=2
            rest(row)=0;
        end
        rest(1)=sum(sig(t2courseindex,2:betarow).*msval(t2courseindex,1:betarow-1));
        rest(2:betarow)=sig(t2courseindex,1)*msval(t2courseindex,1:betarow-1);
%         c=1; d=1;
%         betarow=size(betas,1); alpharow=size(alphas,1);
%         row=alpharow*betarow;
%         if row >=2
%             rest(row)=0;
%         end
%         rest(1)=-1/2*sum(sig(t2courseindex,:).^2)...
%             +d*sum(sig(t2courseindex,2:betarow).*(msval(t2courseindex,1:betarow-1)));
%         rest(2:betarow)=-sig(t2courseindex,2:betarow).*sig(t2courseindex,1);
%         for k=2:alpharow
%             rest(betarow*(k-1)+1:k*betarow)=c*(sig(t2courseindex,1:betarow)...
%                 *msval(t2courseindex,k-1));
%         end
end
rest=rest';



